// Item toplevel class
//--------------------------------
#ifndef ITEM_H
#define ITEM_H
#include "common.h"
#include "actor.h"
#include "bspecial.h"
#include "bitem.h"

class Item : public Behaved, public BIIsItem, public BIIsActor, public BIItemCarrier, public BIOnEaten,
             public BIName, public BISymbol, public BIOnSetFire, public BIOnUpdateBuffs, public BIMemorySymbol {
public:

    Item();
    virtual ~Item();

    // Positioning within the game world
         void SetMap( Map* map, uint x, uint y );
         void SetActor( Creature* c );
    Creature* GetActor() const;
    virtual       Map* GetMap();
    virtual const Map* GetMap() const;

    // Equip
    void Wear( bool wear );
    bool IsWorn() const;
    void Wield( bool wield );
    bool IsWielded() const;

    // Remove - don't delete directly
    virtual void Destroy();
    virtual bool IsDestroyed() const;

    // Priority - affects the order in which items are
    // displayed in inventory
    static bool PrioritySort( const Item* less, const Item* greater );
    static bool CategorySort( const Item* less, const Item* greater );
    static std::string CategoryToString( uint category );

protected:

    virtual bool IsItem( Item** item ) const;
    virtual bool IsActor( Actor** actor ) const;
    virtual bool ItemCarrier( Creature** carrier, bool* worn, bool* wielded ) const;
    virtual bool Symbol( IO::SymList* list ) const;
    virtual bool Name( std::string* name, bool* plural, uint article ) const;
    virtual bool OnSetFire();
    virtual bool OnUpdateBuffs();
    virtual bool MemorySymbol( bool* memory, bool* tileMemory ) const;

private:

    friend class ItemActor;
    void DestroyPrivate();

    class ItemActor : public Actor {
    public:

        ItemActor( Item* item );
        virtual ~ItemActor() { }

        void  SetItem( Item* item );
        Item* GetItem() const;

        virtual void Destroy();

        virtual bool HasBuff( const Buff* buff ) const;
        virtual void GetAllBuffs     ( BuffList& outputList );
        virtual void GetAllBuffs( ConstBuffList& outputList ) const;

        virtual const Behaved* GetBase() const;
        virtual       Behaved* GetBase();

    private:

        friend class Item;
        void DestroyPrivate();
        virtual void Add( Buff* buff );
        virtual void Remove( Buff* buff );

        Item* _item;
        
    };

    ItemActor* _itemActor;
    Creature*  _actor;
    Buff*      _holdBuff;
    Buff*      _wearBuff;
    Buff*      _wieldBuff;
    bool       _destroy;

};

#endif
